package db

import (
	db2 "common/db"
	"go.uber.org/zap"
	"gorm.io/gorm"
)

type Config struct {
	Database string `help:"数据库连接"  devDefault:"sqlite3://$HOME/enode.db" default:"sqlite3://$ROOT/enode.db"`
	LogLevel string `help:"sql日志打印级别" default:"info"`
}

type DB struct {
	log *zap.Logger
	db  *gorm.DB
}

func NewDB(databaseUrl string, log *zap.Logger, logLevel string) (*DB, error) {
	db, err := db2.NewGormDBWithLog(databaseUrl, log, logLevel)
	if err == nil {
		return &DB{db: db, log: log}, nil
	}
	return nil, err
}
